// pages/me/me.js
var QQMapWx = require('../../libs/qqmap-wx-jssdk');
var qqmapsdk = new QQMapWx({
  key: 'YY2BZ-Z2JCQ-KGB54-B7TTS-MQTAQ-EYF44'
});
Page({
  data: {
    userinfo: {},
    TabCur: 0,
    scrollLeft: 0,
    tablist: ["笔记", "收藏", "赞过"],
    noramalData: [{
        id: 1000,
        cover: "/image/sucai/物理老师打篮球一百个只进了三个_1_蛤？_来自小红书网页版.jpg",
        title: "物理老师打篮球一百个只进了三个",
        tx: "/image/sucai/c9ac2f1c-230d-4c80-ba00-401f6c66d92d.png",
        name: "蛤?",
        num: 10000,
        tran_num: "",
        islike: 1,
        tag: ["推荐", "穿搭", "职场"]
      },
      {
        id: 1001,
        cover: "/image/sucai/山东自考成绩_1_非酋_来自小红书网页版.jpg",
        title: "山东自考成绩",
        tx: "/image/sucai/e17c178b-bbc7-48c8-8063-74bcdd7146e9.png",
        name: "非酋?",
        num: 56,
        tran_num: "",
        islike: 0,
        tag: ["推荐", "穿搭", "男高"]
      },
      {
        id: 1002,
        cover: "/image/sucai/后悔没有早点来南昌😭真的太好吃了！！！_1_黑框（live纯享版）_来自小红书网页版.jpg",
        title: "后悔没有早点来南昌😭真的太好吃了！！！",
        tx: "/image/sucai/95d71d59-5a5f-4d61-b918-6837735e2332.png",
        name: "黑框",
        num: 2886,
        tran_num: "",
        islike: 0,
        tag: ["推荐", "美食"]
      },
      {
        id: 1003,
        cover: "/image/sucai/不懂就问，这车能跑过小米su7 Ultra吗？_1_山野睛子_来自小红书网页版.jpg",
        title: "不懂就问，这车能跑过小米su7 Ultra吗？",
        tx: "/image/sucai/2b747730-ccba-4759-b9b0-f1de69fd15f4.png",
        name: "山野睛子",
        num: 4087,
        tran_num: "",
        islike: 1,
        tag: ["推荐", "跑车", "职场"]
      },
      {
        id: 1004,
        cover: "/image/sucai/穷鬼女大学生没踩雷的一套化妆品_1_月昭海_来自小红书网页版.jpg",
        title: "穷鬼女大学生没踩雷的一套化妆品",
        tx: "/image/sucai/96229f7b-ef00-4659-bbaf-d1ef86302bbb.png",
        name: "月昭海",
        num: 9884,
        tran_num: "",
        islike: 1,
        tag: ["推荐", "彩妆", "美女"]
      },
      {
        id: 1005,
        cover: "/image/sucai/推荐九部今年新出国产剧，你看了几部？_1_是张鱼小丸子🎬_来自小红书网页版.jpg",
        title: "推荐九部今年新出国产剧，你看了几部？",
        tx: "/image/sucai/cdd70760-7538-49bd-8899-1f67d64a144d.png",
        name: "是张鱼小丸子🎬",
        num: 657,
        tran_num: "",
        islike: 1,
        tag: ["推荐", "影视", "情感"]
      }
    ]
  },
  onLoad(options) {
  },
  toSet() {
    wx.navigateTo({
      url: '/pages/setDetail/setDetail',
    })
  },
  onShow() {
    this.getUserinfo()
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
    this.onShow()
  },
  toLogin() {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  getUserinfo() {
    let user = wx.getStorageSync('userinfo')
    if (user == "") {
      user = {
        bg: "/image/sucai/彭于晏.jpg",
        headUrl: "/image/sucai/2b747730-ccba-4759-b9b0-f1de69fd15f4.png",
        userName: "请点击头像登录",
        code: "",
        IP_address: "",
        detail: "",
        sex: "",
        taglist: ""
      }
      this.setData({
        userinfo: user
      })
    } else {
      this.getIP()
      console.log(user)
      this.setData({
        userinfo: user
      })
    }
  },
  getIP(){
    let that = this
    wx.getFuzzyLocation({
      type: 'wgs84',
      success(res) {
        console.log(res)
        that.setData({
          location: res.latitude + "," + res.longitude
        })
        qqmapsdk.reverseGeocoder({
          location: that.data.location,
          success: function (res) {
            let province = res.result.address_component.province
            province = province.substring(0, 2)
            let user = that.data.userinfo
            user.IP_address = province
            that.setData({
              userinfo: user
            })
            console.log(user)
          }
        })
      }
    })
  }
})